package d1016;

import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class BookStore {
    static Book[] books = new Book[6];

    static {
        books[0] = new Book(1, "java程序设计", 50.0, 60);
        books[1] = new Book(2, "C++", 40.0, 10);
        books[2] = new Book(3, "PHP", 30.0, 20);
        books[3] = new Book(4, "Python", 25.0, 10);
        books[4] = new Book(5, "web", 45.0, 100);
        books[5] = new Book(6, "mysql", 34.0, 5);
    }

    public BookStore() {
    }

    public static void main(String[] args) {
        showBook(books);
        Person p = new Person("张三");
        Book book = p.buy(books);
        showTotal(p, book);
    }

    public static void showBook(Book[] books) {
        System.out.println("图书编号\t图书价格\t库存\t价格");

        for(int i = 0; i < books.length; ++i) {
            System.out.println(books[i].getId() + "\t" + books[i].getName() + "\t" + books[i].getPrice() + "\t" + books[i].getStorage());
        }

    }

    public static void showTotal(Person p, Book book) {
        System.out.println("请输入购书的数量");
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        Random random = new Random();
        int orderNum = random.nextInt();
        System.out.println("订单编号:" + Math.abs(orderNum));
        System.out.println("购物时间:" + LocalDateTime.now());
        System.out.println("会员:" + p.getName());
        System.out.println("图书名称" + book.getName() + ",单价" + book.getPrice() + "￥,购买数量" + number);
        System.out.println("-----------总计:" + book.getPrice() * (double)number);
    }
}
